package com.MedDroid.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import com.MedDroid.MainApp;
import com.MedDroid.R;
import com.MedDroid.task.LoadSchedulePageTask;

import java.util.ArrayList;

public class SchedulePageActivity extends Activity
{
	public Button btnAddAppointment, btnRequestAppointment;
	public ArrayList<Integer> ListEventID = new ArrayList<Integer>();
	public ArrayList<String> ListNames = new ArrayList<String>();
	public ListView ListEvent;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.schedule_page);

        btnAddAppointment = (Button) findViewById(R.id.btnAddAppointment);
        btnAddAppointment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SchedulePageActivity.this, AddAppointmentActivity.class);
                //EditText editText = (EditText) findViewById(R.id.btnNotificationPage);
                //String message = editText.getText().toString();
                //intent.putExtra(null, message); //EXTRA MESSAGE CAN BE PLACED IN THE NULL
                startActivity(intent);
            }
        });

        btnRequestAppointment = (Button) findViewById(R.id.btnRequestAppoint);
        btnRequestAppointment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SchedulePageActivity.this, RequestAppointmentActivity.class);
                //EditText editText = (EditText) findViewById(R.id.btnNotificationPage);
                //String message = editText.getText().toString();
                //intent.putExtra(null, message); //EXTRA MESSAGE CAN BE PLACED IN THE NULL
                startActivity(intent);
            }
        });
    }

	@Override
	protected void onResume()
	{
		super.onResume();
		new LoadSchedulePageTask(((MainApp)getApplication()).getAuthentication(),((MainApp)getApplication()).getDatabase(), SchedulePageActivity.this).execute();
	}

	public void makeList()
	{
		MainApp.log("Making List.");
		MainApp.log(Integer.toString(ListNames.size()));
		ArrayAdapter<String> adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, ListNames);
		if (ListNames.size() > 0)
		{
			ListEvent.setAdapter(adapter);
			ListEvent.setOnItemClickListener(new AdapterView.OnItemClickListener()
			{
				@Override
				public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
				{
					Intent intent = new Intent(SchedulePageActivity.this, ViewAppointmentActivity.class);
					intent.putExtra("EventID", ListEventID.get(i));
					startActivity(intent);
					}
			});
		}
	}
}